package com.mall507.fivepeaks.activity.mine;

import android.content.Context;
import android.graphics.Color;
import android.location.Address;
import android.location.Geocoder;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.launcher.ARouter;
import com.hzh.frame.comn.callback.HttpCallBack;
import com.hzh.frame.core.HttpFrame.BaseHttp;
import com.hzh.frame.ui.fragment.BaseFM;
import com.hzh.frame.util.StatusBarUtil;
import com.hzh.frame.widget.xtitleview.TitleView;
import com.mall507.comn.model.User;
import com.mall507.comn.tools.UserTools;
import com.mall507.fivepeaks.R;
import com.mall507.fivepeaks.widget.imageview.CircleImageView;
import com.mall507.fivepeaks.widget.imageview.ExpandImageView;

import org.json.JSONObject;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

/**
 * @author
 * @version 1.0
 * @date 2019/7/30
 */
public class MineFM extends BaseFM implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener {

    private View mBaseView;
    private LinearLayout item_yjfk, item_gywm, item_set, userInfo; //意见反馈，关于我们, 设置
    private CircleImageView user_headimage;
    private TextView nickName;
    private TextView personalSign;

    @Override
    public boolean setTitleIsShow() {
        return false;
    }

    @Override
    protected void onCreateBase() {
        mBaseView = setContentView(R.layout.fm_mine_index);
        ((TitleView) mBaseView.findViewById(R.id.title)).addView(StatusBarUtil.createStatusBarView(getActivity(), Color.TRANSPARENT), 0);
        init();
    }

    private void init() {
        userInfo = mBaseView.findViewById(R.id.userInfo);
        user_headimage = mBaseView.findViewById(R.id.user_headimage);
        nickName = mBaseView.findViewById(R.id.nickName);
        personalSign = mBaseView.findViewById(R.id.personalSign);
        item_yjfk = mBaseView.findViewById(R.id.item_yjfk);
        item_gywm = mBaseView.findViewById(R.id.item_gywm);
        item_set = mBaseView.findViewById(R.id.item_set);
        mBaseView.findViewById(R.id.pay).setOnClickListener(this);
        mBaseView.findViewById(R.id.received).setOnClickListener(this);
        mBaseView.findViewById(R.id.waitAssess).setOnClickListener(this);
        mBaseView.findViewById(R.id.refund).setOnClickListener(this);
        item_yjfk.setOnClickListener(this);
        item_gywm.setOnClickListener(this);
        item_set.setOnClickListener(this);
        loadUserInfo();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.userInfo:
                ARouter.getInstance().build("/login/login").navigation(); //登录
                break;
            case R.id.pay:
                ARouter.getInstance().build("/mine/MessageUI").navigation(); //我的消息
                break;
            case R.id.received:
                ARouter.getInstance().build("/mine/CommentRUI").navigation(); //我的收藏
                break;
            case R.id.waitAssess:
                ARouter.getInstance().build("/mine/ReleaseUI").navigation(); //我的发布
                break;
            case R.id.refund:
                ARouter.getInstance().build("/mine/ProblemRUI").navigation(); //我的问题
                break;
            case R.id.item_yjfk:
                ARouter.getInstance().build("/mine/FeedBackUI").navigation(); //意见反馈
                break;
            case R.id.item_gywm:
                ARouter.getInstance().build("/mine/OnWeUI").navigation(); //关于我们
                break;
            case R.id.item_set:
                ARouter.getInstance().build("/mine/SettingUI").navigation(); //设置
                break;
        }
    }
    public void loadUserInfo() {
        if (UserTools.getInstance().getIsLogin()) {
            User user = UserTools.getInstance().getUser();
            user_headimage.setImageURI(user.getHead());
            nickName.setText(user.getNickName());
            if (user.getPersonalSign().equals("null") || user.getPersonalSign() == null){
                personalSign.setText("暂无个性签名");
            }else {
                personalSign.setText(user.getPersonalSign());
            }
            userInfo.setOnClickListener(null);
        } else {
            user_headimage.setImageResource(R.mipmap.base_image_face);
            nickName.setText("点击登录"); 
            personalSign.setText("登录查看更多资料");
            userInfo.setOnClickListener(this);
        }
    }
    
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (getUserVisibleHint()) {
            //界面可见
            user_headimage = mBaseView.findViewById(R.id.user_headimage);
            nickName = mBaseView.findViewById(R.id.nickName);
            personalSign = mBaseView.findViewById(R.id.personalSign);
            loadUserInfo();
        } else {
            //界面不可见 相当于onpause
        }
    }

}
